package cate.game.role.pvp.eliterace.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.pvp.eliterace.data.EliteRaceSpec;
import cate.game.pvp.eliterace.util.EliteRaceSpecUtils;
import easy.java.practice.errorcode.EcResult;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.Objects;

import static cate.game.client.msg.MsgSender.send;
import static cate.game.client.msg.id.MsgIdBEliteRace.ROUND_REQ;
import static cate.game.pvp.eliterace.util.EliteRaceSpecUtils.checkQuerySpec;

@NoArgsConstructor
@ClientMsg(title = "精英赛  回合 请求")
public class EliteRaceRoundReq implements MsgInput {

    public EliteRaceSpec from;
    public EliteRaceSpec to;

    @Override
    public MsgConfig conf() {
        return ROUND_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        EliteRaceSpecUtils.SpecPair pair = checkQuerySpec(from, to,
                cc.getRole().getGame().pvp.eliteRace.getDataManager().getData().getSpec());
        if (Objects.isNull(pair)) {
            game.notice.message(cc.getRole(), "参数错误!");
            return;
        }

        this.from = pair.getFrom();
        this.to = pair.getTo();

        EcResult<EliteRaceRoundResp> r
                = game.pvp.eliteRace.getHandler().handleRoundReq(cc.getRole().getUid(), this);
        if (r.ok()) {
            send(cc::sendNow, r.data);
        }
    }
}
